﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AgentBar.Common;
using System.Configuration;
using Cpfmsgacxa;

namespace AgentBar
{
    public partial class FrmSelectFoward : Form
    {
        private string Language
        {
            get
            {
                string language = ConfigurationManager.AppSettings["LAN"];
                if (string.IsNullOrEmpty(language)) language = "JP";
                return language;
            }
        }

        public frmAgentBar MainF;
        public FrmSelectFoward(frmAgentBar parentForm)
        {
            MainF = parentForm;
            InitializeComponent();
            InitialCombox();
        }

        private void FrmSelectFoward_Load(object sender, EventArgs e)
        {
            LanguageResourceManager _ResourceManager = new LanguageResourceManager(Language);
            PicBoxStatus picOk = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040020"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\ButtonOK.png"), PictureBox = this.picFoward, Enabled = false };
            PicBoxStatus piccancel = new PicBoxStatus() { Title = "キャンセル", BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\ButtonCancel.png"), PictureBox = this.picCancel, Enabled = true };
            PictureBoxTool.DrawInPictureBox(picOk);
            PictureBoxTool.DrawInPictureBox(piccancel);
        }

        private void InitialCombox()
        {
            try
            {
                int count = MainF.g_objListParams.GetLongDefault("Count", 0);
                for (int i = 1; i <= count; i++)
                {
                    string sID = MainF.g_objListParams.GetStringDefault("ID" + i.ToString(), "");
                    string sDisp = MainF.g_objListParams.GetString("Disp" + i.ToString());
                    if (sID != "")
                    {
                        ListItem item = new ListItem(sID, sDisp);
                        this.cmbAgent.Items.Add(item);
                    }
                }
                if (count > 0) this.cmbAgent.SelectedIndex = 0;

                count = MainF.g_objGroupList.GetLongDefault("Count", 0);
                count = count / 2;
                for (int i = 1; i <= count; i++)
                {
                    string sID = MainF.g_objGroupList.GetStringDefault("ID" + i.ToString(), "");
                    string sDisp = MainF.g_objGroupList.GetString("Disp" + i.ToString());
                    if (sID != "")
                    {
                        ListItem item = new ListItem(sID, sDisp);
                        this.cmbSkill.Items.Add(item);
                    }
                }
                if (count > 0) this.cmbSkill.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                MainF._strReturnValueFromSelectForward = "cancel";
                MessageBox.Show(ex.Message);
                this.Dispose();
            }
        }

        private void picFoward_Click(object sender, EventArgs e)
        {
            if (rdbSkill.Checked)
            {
                if (this.cmbSkill.SelectedValue != null && this.cmbSkill.SelectedValue.ToString() != "")
                    MainF._strReturnValueFromSelectForward = this.cmbSkill.SelectedValue.ToString();
                else
                    MainF._strReturnValueFromSelectForward = "cancel";
            }
            else if (this.rdbAgent.Checked)
            {
                if (this.cmbAgent.SelectedValue != null && this.cmbAgent.SelectedValue.ToString() != "")
                    MainF._strReturnValueFromSelectForward = this.cmbAgent.SelectedValue.ToString();
                else
                    MainF._strReturnValueFromSelectForward = "cancel";
            }
            else
            {
                MainF._strReturnValueFromSelectForward = "cancel";
            }
            this.Dispose();
        }

        private void picCancel_Click(object sender, EventArgs e)
        {
            MainF._strReturnValueFromSelectForward = "cancel";
            this.Dispose();
        }

        private void rdbSkill_Click(object sender, EventArgs e)
        {
            this.cmbAgent.Enabled = false;
            this.cmbSkill.Enabled = true;
        }

        private void rdbAgent_Click(object sender, EventArgs e)
        {
            this.cmbAgent.Enabled = true;
            this.cmbSkill.Enabled = false;
        }

        private void FrmSelectFoward_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                picFoward_Click(null, null);
            }
            else if (e.KeyCode == Keys.Escape)
            {
                picCancel_Click(null, null);
            }
        }

        private void FrmSelectFoward_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }
    }
}
